package main

import "fmt"

/* 给定数组索引与值围成最大面积*/
func main()  {
	nums := []int{1,8,6,2,5,4,8,3,7}
	area := getArea(nums)
	fmt.Println(area)
}

func getArea(nums []int) int {
	var w,h int
	var area int
	i, r := 0,len(nums) - 1
	for i < r {
		w = r - i
		h = 0
		if nums[i] < nums[r] {
			h = nums[i]
			i++
		}else{
			h = nums[r]
			r--
		}
		wh := w * h
		if wh > area {
			area = wh
		}
	}
	return area
}